<script lang="ts">
import { defineComponent } from "vue";

import PopupComp from "./popup.vue";

export default defineComponent({
  components: { PopupComp },
  props: {
    modelValue: Boolean,
    title: { type: String, default: "提示" },
    content: String,
    showCancel: { type: Boolean, default: true },
    cancelText: { type: String, default: "取消" },
    confirmText: { type: String, default: "确定" },
    width: { type: String, default: "80vw" },
  },
  emits: {
    "update:modelValue": (value: boolean) => typeof value === "boolean",
    cancel: () => true,
    confirm: () => true,
  },
  setup(props, ctx) {
    const updateModelValue = (value: boolean) => {
      ctx.emit("update:modelValue", value);
    };
    const cancelClcik = () => {
      ctx.emit("cancel");
      updateModelValue(false);
    };
    const confirmClcik = () => {
      ctx.emit("confirm");
      updateModelValue(false);
    };
    return { cancelClcik, confirmClcik };
  },
});
</script>

<template>
  <popup-comp :modelValue="modelValue" style="transform: translateY(-60%)">
    <div class="popup-modal" :style="{ width }">
      <div class="popup-modal-title">{{ title }}</div>
      <div class="popup-modal-content">
        <slot v-if="$slots.default" />
        <template v-else>{{ content }}</template>
      </div>
      <div class="popup-modal-operate">
        <div class="popup-modal-cancel" v-if="showCancel" @click="cancelClcik">
          {{ cancelText }}
        </div>
        <div class="popup-modal-confirm" @click="confirmClcik">
          {{ confirmText }}
        </div>
      </div>
    </div>
  </popup-comp>
</template>

<style lang="less">
.popup-modal {
  padding: 20px;
  // border-radius: 10px;
  // background-color: #ffffff;
  box-sizing: border-box;

  .popup-modal-title {
    padding-top: 9px;
    font-size: 18px;
    color: #333333;
    line-height: 20px;
    text-align: center;
    font-weight: bold;
  }

  .popup-modal-content {
    margin-top: 20px;
    font-size: 15px;
    color: #666666;
    line-height: 21px;
    text-align: center;
    white-space: pre-line;
  }

  .popup-modal-operate {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 30px;
  }

  .popup-modal-cancel,
  .popup-modal-confirm {
    flex-grow: 1;
    width: 100%;
    min-width: 0;
    max-width: 135px;
    margin-right: 10px;
    font-size: 15px;
    color: #40c17f;
    line-height: 40px;
    text-align: center;
    border-radius: 5px;
    background-color: #f4f8f6;
  }

  .popup-modal-confirm {
    margin-right: 0;
    color: #ffffff;
    background-color: #40c17f;
  }
}
</style>
